//
//  ICMBalanceCouponCell.m
//  ICrEAM
//
//  Created by ysw on 2016/11/26.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMBalanceCouponCell.h"

@interface ICMBalanceCouponCell ()

@property (nonatomic, strong) UIButton *operateButton;

@property (nonatomic, strong) UILabel *orderLabel;

@property (nonatomic, strong) UILabel *userNameLabel;

@property (nonatomic, strong) UILabel *couponTypeLabel;

@property (nonatomic, strong) UILabel *couponPriceLabel;

@property (nonatomic, strong) UILabel *quantityLabel;

@property (nonatomic, strong) UILabel *usedQuantityLabel;

@property (nonatomic, strong) UILabel *timeLabel;

@end

@implementation ICMBalanceCouponCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *cellView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth-ActualWidth(100), ActualHeight(30))];
        cellView.backgroundColor = BackgroundColor_Gray;
        [self.contentView addSubview:cellView];
        
        
        UIButton *operateButton = [UIButton buttonWithType:UIButtonTypeCustom];
        operateButton.frame = CGRectMake(0, ActualHeight(5), ActualWidth(50), ActualHeight(20));
        [operateButton setImage:[UIImage imageNamed:@"btn_tableview_delete"] forState:UIControlStateNormal];
        operateButton.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 15);
        [operateButton addTarget:self action:@selector(clickDeleteButton) forControlEvents:UIControlEventTouchUpInside];
        [cellView addSubview:operateButton];
        self.operateButton = operateButton;
        
        UIView *firstSep = [[UIView alloc] initWithFrame:CGRectMake(operateButton.rightEdge, 0, 1, cellView.height)];
        firstSep.backgroundColor = BorderColor_Gray;
        [cellView addSubview:firstSep];
        
        UILabel *orderLabel = [self createLabelWithText:@"" frame:CGRectMake(firstSep.rightEdge, operateButton.y, ActualWidth(50), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [cellView addSubview:orderLabel];
        self.orderLabel = orderLabel;
        
        UIView *secondSep = [[UIView alloc] initWithFrame:CGRectMake(orderLabel.rightEdge, 0, 1, cellView.height)];
        secondSep.backgroundColor = BorderColor_Gray;
        [cellView addSubview:secondSep];
        
        UILabel *userNameLabel = [self createLabelWithText:@"" frame:CGRectMake(secondSep.rightEdge, operateButton.y, ActualWidth(130), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [cellView addSubview:userNameLabel];
        self.userNameLabel = userNameLabel;
        
        UIView *thirdSep = [[UIView alloc] initWithFrame:CGRectMake(userNameLabel.rightEdge, 0, 1, cellView.height)];
        thirdSep.backgroundColor = BorderColor_Gray;
        [cellView addSubview:thirdSep];
        
        UILabel *couponTypeLabel = [self createLabelWithText:@"" frame:CGRectMake(thirdSep.rightEdge, operateButton.y, ActualWidth(120), ActualHeight(15)) textAlignment:NSTextAlignmentLeft];
        [cellView addSubview:couponTypeLabel];
        self.couponTypeLabel = couponTypeLabel;
        
        UIView *fourthSep = [[UIView alloc] initWithFrame:CGRectMake(couponTypeLabel.rightEdge, 0, 1, cellView.height)];
        fourthSep.backgroundColor = BorderColor_Gray;
        [cellView addSubview:fourthSep];
        
        UILabel *couponPriceLabel = [self createLabelWithText:@"" frame:CGRectMake(fourthSep.rightEdge, operateButton.y, ActualWidth(120), ActualHeight(15)) textAlignment:NSTextAlignmentRight];
        [cellView addSubview:couponPriceLabel];
        self.couponPriceLabel = couponPriceLabel;
        
        UIView *fifthSep = [[UIView alloc] initWithFrame:CGRectMake(couponPriceLabel.rightEdge, 0, 1, cellView.height)];
        fifthSep.backgroundColor = BorderColor_Gray;
        [cellView addSubview:fifthSep];
        
        UILabel *quantityLabel = [self createLabelWithText:@"" frame:CGRectMake(fifthSep.rightEdge, operateButton.y, ActualWidth(120), ActualHeight(15)) textAlignment:NSTextAlignmentRight];
        [cellView addSubview:quantityLabel];
        self.quantityLabel = quantityLabel;
        
        UIView *sixthSep = [[UIView alloc] initWithFrame:CGRectMake(quantityLabel.rightEdge, 0, 1, cellView.height)];
        sixthSep.backgroundColor = BorderColor_Gray;
        [cellView addSubview:sixthSep];
        
        UILabel *usedQuantityLabel = [self createLabelWithText:@"" frame:CGRectMake(sixthSep.rightEdge, operateButton.y, ActualWidth(120), ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [cellView addSubview:usedQuantityLabel];
        self.usedQuantityLabel = usedQuantityLabel;
        
        UIView *seventhSep = [[UIView alloc] initWithFrame:CGRectMake(usedQuantityLabel.rightEdge, 0, 1, cellView.height)];
        seventhSep.backgroundColor = BorderColor_Gray;
        [cellView addSubview:seventhSep];
        
        UILabel *timeLabel = [self createLabelWithText:@"" frame:CGRectMake(seventhSep.rightEdge, operateButton.y, ScreenWidth-ActualWidth(40)-usedQuantityLabel.rightEdge, ActualHeight(15)) textAlignment:NSTextAlignmentCenter];
        [cellView addSubview:timeLabel];
        self.timeLabel = timeLabel;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (UILabel *)createLabelWithText:(NSString *)text frame:(CGRect)frame textAlignment:(NSTextAlignment)textAlignment{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = ContentFont;
    label.textColor = ContentTextColor_Black;
    label.textAlignment = textAlignment;
    return label;
}

- (void)clickDeleteButton {
    if ([self.delegate respondsToSelector:@selector(deleteCouponWithCell:)]) {
        [self.delegate deleteCouponWithCell:self];
    }
}

- (void)creatCellWithModel:(ICMBalanceCouponModel *)model
{
    self.orderLabel.text = [NSString stringWithFormat:@"%ld",(long)self.indexPath.row+1];
    self.userNameLabel.text = model.CUSTOMER_NAME;
    self.couponTypeLabel.text = model.COUPON_TYPE_NAME;
    self.couponPriceLabel.text = model.COUPON_UVAL;
    self.quantityLabel.text = model.COUPON_QUANTITY;
    self.usedQuantityLabel.text = model.USED_QUANTITY;
    self.timeLabel.text = model.COUPON_OUT_DATE;
    
}

@end
